import AMapLoader from '@amap/amap-jsapi-loader'
import '@amap/amap-jsapi-types'

const key = "d945ba1868584ed05c1a771064102387"

window._AMapSecurityConfig = {
    securityJsCode:'e67093e616e868343230a299397a5778',
}

export async function loadAMap(options: Omit<Parameters<typeof AMapLoader.load>[0], 'key' | 'version'>): Promise<void> {
    const amap = await AMapLoader.load({
        ...options,
        key: key,
        version: '2.0'
    })
}

type LocalCityResult = {
    adcode: string
    bounds: AMap.Bounds
    city: string,
    province: string
}

let citySearch: any

export async function localCity(): Promise<LocalCityResult> {
    if (!citySearch) {
        await loadAMap({
            plugins: ['AMap.CitySearch']
        })
        citySearch = new AMap.CitySearch()
    }
    return new Promise((resolve, reject) => {
        citySearch.getLocalCity(function (status, result) {
            if (status === "complete") {
                resolve(result as LocalCityResult)
            } else {
                reject(new Error(JSON.stringify(result)))
            }
        })
    })
}

let geolocation: any

export async function name(params:type) {
    
}